//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreatePicture {
        private readonly IPictureRepository _pictureRepository;

        public CreatePicture(IPictureRepository pictureRepository) {
            _pictureRepository = pictureRepository;
        }

        public void Execute(Guid userId, ICreatePictureCommand pictureForm) {
            if (pictureForm == null)
                throw new ArgumentNullException("pictureForm");

            try {
                var picture = pictureForm.ConvertToEntity();
                _pictureRepository.Create(picture);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
